package com.example.demo.controller;

import com.example.demo.controller.bean.Result;
import com.example.demo.dto.ClothingRequestDTO;
import com.example.demo.dto.TaskRequestDTO;
import com.example.demo.mapper.entity.*;
import com.example.demo.service.ClothingManageService;
import com.example.demo.service.TaskManageService;
import com.example.demo.utils.PageBo;
import com.example.demo.utils.PageVo;
import com.example.demo.utils.TreeBo;
import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

import java.util.List;

@RequestMapping("taskManage")
@Api(value = "任務管理接口", tags = {"任務管理接口"})
@RestController
@Slf4j
public class TaskManageController {
    @Autowired
    private TaskManageService service;
    @ResponseBody
    @ApiOperation(value = "获取任務列表接口")
    @RequestMapping(value = "getTaskList", method = {RequestMethod.POST})
    public Result<PageVo<Task>> getTaskList(@RequestBody PageBo pageBo) {
        PageVo<Task> list = service.getTaskList(pageBo);
        return Result.ok(list);
    }
    @ResponseBody
    @ApiOperation(value = "搜索任務接口")
    @RequestMapping(value = "searchTask", method = {RequestMethod.POST})
    public Result<PageVo<TaskRequestDTO>> getListSearch(@RequestBody TaskRequestDTO request) {
        PageBo pageBo = new PageBo();
        pageBo.setPageNum(request.getPageNum());
        pageBo.setPageSize(request.getPageSize());

        List<Task> list = service.searchTask(request);
        PageVo<TaskRequestDTO> logs = new PageVo<>(pageBo,list);

        return Result.ok(logs);
    }

    @ApiOperation(value = "新增任務")
    @PostMapping("/addTask")
    public Result<String> addTask(@RequestBody TaskRequestDTO request) {
        JsonNode jsonNode = request.getAttributes();
        request.setAttributesAwarded(jsonNode.toString());
        return service.addTask(request);
    }

    @ResponseBody
    @ApiOperation("删除任務接口")
    @RequestMapping(value = "deleteTask", method = {RequestMethod.POST})
    public Result<String> delete(@RequestBody Task task) {
        return service.deleteTask(task);
    }

    @ResponseBody
    @ApiOperation("批量删除接口")
    @RequestMapping(value ="batchDeleteTask", method = {RequestMethod.POST})
    public Result<String> deleteList(@RequestBody List<Task> taskList) {
        service.batchDeleteTask(taskList);
        return Result.ok("删除成功");
    }

    @GetMapping("getTotalStudent")
    @ApiOperation(value = "獲取學生人數接口")
    @ResponseBody
    public int getTotalStudent(){
        return service.getTotalStudent();
    }

    @ApiOperation("获取专业列表")
    @RequestMapping("getTotalQuestions/{bankId}")
    public Result<Object> getTotalQuestions(@PathVariable("bankId") int bankId) {
        int totalQuestions = service.getTotalQuestions(bankId);
        return Result.ok(totalQuestions);
    }
    @ApiOperation("获取學院人數")
    @RequestMapping("totalCollegeStudent/{collegeId}")
    public Result<Object> totalCollegeStudent(@PathVariable("collegeId") int collegeId) {
        int totalStudent = service.getCollegeStudent(collegeId);
        return Result.ok(totalStudent);
    }
    @ApiOperation("获取學院人數")
    @RequestMapping("totalMajorStudent/{majorId}")
    public Result<Object> totalMajorStudent(@PathVariable("majorId") int majorId) {
        int totalStudent = service.getMajorStudent(majorId);
        return Result.ok(totalStudent);
    }

    @ApiOperation("获取班級人數")
    @RequestMapping("totalClassStudent/{clazz}")
    public Result<Object> totalClassStudent(@PathVariable("clazz") int clazz) {
        int totalStudent = service.getClassStudent(clazz);
        return Result.ok(totalStudent);
    }
    @ApiOperation("获取學生人數")
    @RequestMapping("totalStudent/{studentNumber}")
    public Result<Object> totalStudent(@PathVariable("studentNumber") String studentNumber) {
        int totalStudent = service.getStudent(studentNumber);
        return Result.ok(totalStudent);
    }
}
